//
//  DWTimerProxy.m
//  OCAPPDemo
//
//  Created by 杨冬武 on 2021/4/19.
//

#import "DWTimerProxy.h"

@interface DWTimerProxy ()

@property (nonatomic, weak) id aTarget;
@property (nonatomic, assign) SEL aSelector;

@end

@implementation DWTimerProxy

+ (instancetype)proxyWithTarget:(id)aTarget {
    //继承自NSProxy, 不需要调用 init 方法, 调用会报错, 因为本事没有 init
    DWTimerProxy *proxy = [self alloc];
    proxy.aTarget = aTarget;
    return proxy;
}

#pragma mark - 快速消息转发

/// 快速消息转发(如果继承NSObject, 可以直接快速消息转发, 但是继承自NSProxy更加高效, 不会走这个方法)
/// @param aSelector 消息
//- (id)forwardingTargetForSelector:(SEL)aSelector {
//    return self.aTarget;
//}

#pragma mark - 完全消息转发

- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
    return [self.aTarget methodSignatureForSelector:sel];
}

- (void)forwardInvocation:(NSInvocation *)invocation {
    [invocation invokeWithTarget:self.aTarget];
}

- (void)dealloc {
    NSLog(@"%s", __FUNCTION__);
}

@end
